package com.alibaba.cloud.demo.service;

import com.alibaba.cloud.demo.config.ClientSource;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * created by wuquan at 05/07/2021
 * ^_^ ^_^
 */
@Component
@EnableBinding({Source.class, ClientSource.class})
public class StreamProductService {


    @Autowired
    private Source source;

    @Autowired
    private ClientSource clientSource;


    public void publish(JSONObject msg, Map<String, Object> properties) {
        MessageHeaders messageHeaders = new MessageHeaders(properties);
        Message<JSONObject> message = MessageBuilder.createMessage(msg, messageHeaders);
        source.output().send(message);
    }

    public void publish1(JSONObject msg, Map<String, Object> properties) {
        MessageHeaders messageHeaders = new MessageHeaders(properties);
        Message<JSONObject> message = MessageBuilder.createMessage(msg, messageHeaders);
        clientSource.output().send(message);
    }





}
